using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter04
{
	/// <summary>
	/// Example07: The End of the Ski Jump
	/// A ski-jumper leaves the ski track moving in the horizontal 
	/// direction with a speed of 25.0 m/s, as shown in 
	/// Figure 4.16. The landing incline below him falls off 
	/// with a slope of 35.0^{\circle}. Where does he land on the incline?
	/// x_f = 89.3 m, y_f = -62.5 m
	/// </summary>
	public class Example07
	{
		public Example07()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			// x = v.X*t;
			// y = -0.5*g*t^2;
			// y = -tan(35degree)*x;

			L.Velocity v = new L.Velocity();
			v.X = 25.0;

            Science.Mathematics.Calculus.PolynomialFunction poly = new Science.Mathematics.Calculus.PolynomialFunction();
			poly.MaximumPower = 2;
			poly.Which = 0;
			poly.Coefficient = 0.0;
			poly.Which = 1;
			poly.Coefficient = Math.Tan(35.0*Math.PI/180.0);
			poly.Which = 2;
			poly.Coefficient = -0.5*L.Constant.AccelerationOfGravity/v.X/v.X;
			poly.FindRoot();
			double x1 = poly.Root[0].Real;
			double x2 = poly.Root[1].Real;

			double x;
			if(x2 > x1) x = x2;
			else x = x1;

			double y = -Math.Tan(35.0*Math.PI/180.0)*x;
			result+=Convert.ToString(x);
			result+="   "+Convert.ToString(y);
		}
	}
}
